package com.tsn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tsn.common.Dto.AttentionDto;
import com.tsn.common.Result;
import com.tsn.entity.Attention;
import com.tsn.mapper.AttentionMapper;
import com.tsn.service.AttentionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 关注收藏表 服务实现类
 * </p>
 *
 * @author tsn
 * @since 2021-09-07
 */
@Service
public class AttentionServiceImpl extends ServiceImpl<AttentionMapper, Attention> implements AttentionService {
    @Autowired
    private AttentionMapper attentionMapper;
    @Override
    public Result getMyNumber(Integer userId) {
        AttentionDto attentionDto = new AttentionDto();
        QueryWrapper<Attention> attentionQueryWrapper = new QueryWrapper<>();
        attentionQueryWrapper.eq("type",0);
        attentionQueryWrapper.eq("user_id",userId);

        Integer attentionNumber = attentionMapper.selectCount(attentionQueryWrapper);

        QueryWrapper<Attention> followQueryWrapper = new QueryWrapper<>();
        followQueryWrapper.eq("type",0);
        followQueryWrapper.eq("attention_id",userId);
        Integer followNumber = attentionMapper.selectCount(followQueryWrapper);
        attentionDto.setAttentionNumber(attentionNumber);
        attentionDto.setFollowNumber(followNumber);


        return Result.success("查询成功",attentionDto);
    }

    @Override
    public Result listMyAttention(Integer userId) {
        return Result.success(attentionMapper.listMyAttention(userId));
    }

    @Override
    public Result listAttentionMe(Integer userId) {
        return Result.success(attentionMapper.listAttentionMe(userId));
    }
}
